export class Filter {
  /**
   *
   * @param {String} op
   * @param {Array<FilterRule>} rules
   * @param {Array<Filter>} groups
   */
  constructor(op, rules, groups) {
    this.op = op
    this.rules = rules
    this.groups = groups
  }
}

export class FilterRule {
  /**
   *
   * @param {String} field
   * @param {String} op
   * @param {any} value
   */
  constructor(field = '', op = '', value = '') {
    this.field = field
    this.op = op
    this.value = value
  }

  static newRule(field = '', op = '', value = '') {
    return new FilterRule(field, op, value)
  }

  setValue(value) {
    if (value) {
      this.value = value
    }
    return this
  }

  setField(field) {
    this.field = field
    return this
  }

  setOp(op) {
    this.op = op
    return this
  }

  like(value) {
    this.op = 'like'
    this.setValue(value)
    return this
  }

  likeRight(value) {
    this.op = 'likeRight'
    this.setValue(value)
    return this
  }

  eq(value) {
    this.op = 'eq'
    this.setValue(value)
    return this
  }

  val(value) {
    this.value = value
    return this
  }
}
